---
title: Getting Started
description: Get started with Memory in 5 minutes
---

Get up and running with LangCrew Memory in just a few minutes. This guide covers basic setup and common usage patterns.

## Installation

Install LangCrew with memory support:

```bash
# Install LangCrew
uv add langcrew
```

## Basic Usage

### 1. Simple Memory Setup

```python
from langcrew import Agent, Crew

# Create memory configuration - just enable it!
memory_config = True  # Uses default settings with all memory types enabled

# Create agent with memory
agent = Agent(
    role="Memory Assistant",
    goal="Remember and use information from our conversations",
    backstory="You are an AI assistant with excellent memory capabilities"
)

# Create crew with shared memory
crew = Crew(
    agents=[agent],
    memory=memory_config
)
```

### 2. Run Your First Memory-Enabled Conversation

```python
# First conversation
result1 = crew.kickoff(
    inputs={"user_input": "My name is Alice and I love pizza"},
    thread_id="conversation_1"
)

# Later conversation - agent remembers Alice
result2 = crew.kickoff(
    inputs={"user_input": "What food do I like?"},
    thread_id="conversation_1"  # Same thread ID
)

print(result2)  # Agent will remember Alice likes pizza
```

### 3. Persistent Memory with SQLite

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig

# Persistent memory configuration
memory_config = MemoryConfig(
    provider="sqlite",
    connection_string="sqlite:///my_memory.db",
    short_term=ShortTermMemoryConfig(enabled=True),
    long_term=LongTermMemoryConfig(enabled=True)
)

crew = Crew(agents=[agent], memory=memory_config)

# Memory persists across program restarts
result = crew.kickoff(
    inputs={"user_input": "Remember that I work at TechCorp"},
    thread_id="user_alice"
)
```

## Memory Types in Action

### Short-term Memory

Remembers recent conversation history within a session:

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig

# Configure short-term memory
memory_config = MemoryConfig(
    short_term=ShortTermMemoryConfig(enabled=True)
)

# Agent will remember context from recent messages
crew = Crew(agents=[agent], memory=memory_config)
```

### Long-term Memory

Stores important knowledge across sessions:

```python
from langcrew.memory import LongTermMemoryConfig

# Configure long-term memory
memory_config = MemoryConfig(
    long_term=LongTermMemoryConfig(
        enabled=True,
        app_id="my-app"  # RECOMMENDED for production
    )
)

# Agent learns and remembers important facts
crew = Crew(agents=[agent], memory=memory_config)
```

## Configuration Examples

### Development Setup (In-Memory)

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig

memory_config = MemoryConfig(
    provider="memory",  # Fast, no persistence
    short_term=ShortTermMemoryConfig(enabled=True),
    long_term=LongTermMemoryConfig(enabled=True)
)
```

### Production Setup (PostgreSQL)

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig

memory_config = MemoryConfig(
    provider="postgresql",
    connection_string="postgresql://user:pass@localhost:5432/memory_db",
    short_term=ShortTermMemoryConfig(enabled=True),
    long_term=LongTermMemoryConfig(enabled=True)
)
```

### Local Development (SQLite)

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig, LongTermMemoryConfig

memory_config = MemoryConfig(
    provider="sqlite",
    connection_string="sqlite:///development.db",
    short_term=ShortTermMemoryConfig(enabled=True),
    long_term=LongTermMemoryConfig(enabled=True)
)
```

## Common Patterns

### Customer Service Agent

```python
from langcrew.memory import MemoryConfig, ShortTermMemoryConfig

# Memory-enabled customer service
memory_config = MemoryConfig(
    provider="sqlite",
    connection_string="sqlite:///customer_service.db",
    short_term=ShortTermMemoryConfig(enabled=True)
)

service_agent = Agent(
    role="Customer Service Representative",
    goal="Provide personalized customer support",
    backstory="You remember customer history and preferences"
)

crew = Crew(agents=[service_agent], memory=memory_config)

# Each customer gets their own thread
result = crew.kickoff(
    inputs={"user_input": "I need help with my order"},
    thread_id=f"customer_{customer_id}"
)
```

### Learning Assistant

```python
from langcrew.memory import LongTermMemoryConfig

# Memory-enabled learning assistant
memory_config = MemoryConfig(
    provider="sqlite",
    connection_string="sqlite:///learning.db",
    long_term=LongTermMemoryConfig(
        enabled=True,
        app_id="learning-assistant"
    )
)

tutor = Agent(
    role="Personal Tutor",
    goal="Adapt teaching based on student progress",
    backstory="You remember what students have learned and their difficulties"
)

crew = Crew(agents=[tutor], memory=memory_config)
```


## Troubleshooting

### Memory Not Persisting

- Check your `connection_string` format
- Ensure database permissions are correct
- Verify the database file/connection is accessible

### High Memory Usage

- Use connection pooling for database providers
- Consider using SQLite/PostgreSQL instead of in-memory

### Slow Performance

- Use PostgreSQL for production workloads
- Enable connection pooling for database providers
- Consider memory provider for development/testing
